<?php
namespace app\front\logic;
use think\facade\Db;

class MemberGradeLogic{
	public static $init;
	static function init(){
		if (!isset(self::$init)) {//判断是否以前创建了当前类的实例
            $c = __CLASS__;//获取类名
            self::$init = new static;//如果没有创建，实例化当前类，这里实现类只实例化一次
        }
        return self::$init;//返回类的实例
	}

	//获取列表
	function getGradeList($lang='zh'){
		$fields = "id,level,gift_rate,recharge_amount,invitation_rate,from_invitation_rate";
		if($lang=='zh'){
			$fields .= ",grade_ico,grade_name,content";
		}else{
			$fields .= ",grade_ico,grade_name_en as grade_name,content_en as content";
		}
		// echo $fields;
		$list = Db::name('member_grade')
					->field($fields)
					->where('status',1)
					->order('level asc')
					->select();
		return $list;
	}

	//获取具体的等级信息
	function getGradeInfo($lang='zh', $level=1){
		$fields = "gift_rate";
		if($lang=='zh'){
			$fields .=",grade_name";
		}else{
			$fields .= ",grade_name_en as grade_name";
		}
		$info = Db::name('member_grade')
				->field($fields)
				->where('level', $level)
				->where('status', 1)
				->find();
		return $info;
	}
}